// Player Tank Class - Stage 3
#pragma once
#include "GameObject.h"
#include <d3d9.h>
#include <d3dx9.h>
#include <vector>

class PlayerTank : public GameObject
{
public:
    PlayerTank();
    virtual ~PlayerTank();

    bool Initialize(LPDIRECT3DDEVICE9 device, const D3DXVECTOR3& startPos);
    void Update(float deltaTime) override;
    void Render(LPDIRECT3DDEVICE9 device) override;
    void Cleanup() override;

    // Input handling
    void ProcessInput(float deltaTime);
    void ProcessMouseInput(int deltaX, int deltaY, float deltaTime);
    bool IsKeyDown(int vKey);

    // Combat
    void TakeDamage(float damage);
    void Shoot();
    bool IsDead() const { return m_health <= 0.0f; }
    float GetHealth() const { return m_health; }
    float GetMaxHealth() const { return m_maxHealth; }

    // Turret control
    float GetTurretYaw() const { return m_turretYaw; }
    D3DXVECTOR3 GetTurretDirection() const;
    D3DXVECTOR3 GetGunDirection() const;
    D3DXVECTOR3 GetGunPosition() const;

    // Environment
    void SetTerrain(class Terrain* terrain) { m_pTerrain = terrain; }
    void SetObstacles(const std::vector<GameObject*>* obstacles) { m_pObstacles = obstacles; }

    // Properties
    float GetSpeed() const { return m_speed; }
    float GetTurnSpeed() const { return m_turnSpeed; }

private:
    void UpdateMovement(float deltaTime);
    void UpdateTurret(float deltaTime);
    bool CheckCollisionAtPosition(const D3DXVECTOR3& newPos);

    // Model meshes
    LPD3DXMESH m_pBodyMesh;        // 车体
    LPD3DXMESH m_pTurretMesh;      // 炮塔
    LPD3DXMESH m_pBarrelMesh;      // 炮管
    LPD3DXMESH m_pDirectionMesh;   // 方向指示三角锥
    LPDIRECT3DTEXTURE9 m_pTexture;

    // Combat stats
    float m_health;
    float m_maxHealth;
    float m_shootCooldown;
    float m_currentCooldown;

    // Movement
    class Terrain* m_pTerrain;
    const std::vector<GameObject*>* m_pObstacles;
    float m_speed;              // 25 units/sec (5x model size)
    float m_turnSpeed;          // 90 degrees/sec

    // Turret control
    float m_turretYaw;          // 炮塔水平旋转（相对车体）
    float m_turretTurnSpeed;    // 炮塔旋转速度

    // Input
    HWND m_hWnd;
};
